<?php
/* Filename:	update_entry.php
 * Author:		Kelly Pang		
 * Date:		01.07.2013
 * Purpose:		Update entry into db
 * 
 */

include_once("config.php");
include_once("functions.php");

if ($_DEBUG['mode']) {
	error_reporting(E_ERROR);
}
else {
	error_reporting(0);
}

connectDB();

$type = $_REQUEST['type'];
$waitlistID = $_REQUEST['id'];
$val = $_REQUEST['val'];
$entryID = $_REQUEST['entryID'];

$val = mysql_escape_string($val);

$sql_str = "select primarycontactID from Waitlist where ID = $waitlistID";
$result = mysql_query($sql_str);
$row = mysql_fetch_array($result);

$contactID = $row['primarycontactID'];

// Update Name
if ($type == $conf['NAME']) {	
	$sql_str = "update Customer set firstname = \"$val\" where ID = $contactID";
	$result = mysql_query($sql_str);
	debugMsg ("$result :: $sql_str :: $type");
	
	//echo "<input type=\"text\" class=\"name\" placeholder=\"Enter Name\" value=\"$val\" onchange=\"update_entry($entryID, '$type', $waitlistID, this.value)\"/>";
	
	// verify
	$sql_str = "select firstname from Customer where ID = $contactID";
	$result = mysql_query($sql_str);
	$row = mysql_fetch_array($result);
	$val = $row['firstname'];
	
	echo getAjaxNameHtmlResponse($entryID, $type, $waitlistID, $val);
}

// Update Email
if ($type == $conf['EMAIL']) {
	$sql_str = "update Customer set email = \"$val\" where ID = $contactID";
	$result = mysql_query($sql_str);
	
	// verify
	$sql_str = "select email from Customer where ID = $contactID";
	$result = mysql_query($sql_str);
	$row = mysql_fetch_array($result);
	$val = $row['email'];
	
	echo getAjaxEmailHtmlResponse($entryID, $type, $waitlistID, $val);
}

// Update Phone
if ($type == $conf['PHONE']) {
	$sql_str = "update Customer set phone = \"$val\" where ID = $contactID";
	$result = mysql_query($sql_str);
	
	// verify
	$sql_str = "select phone from Customer where ID = $contactID";
	$result = mysql_query($sql_str);
	$row = mysql_fetch_array($result);
	$val = $row['phone'];
	
	echo getAjaxPhoneHtmlResponse($entryID, $type, $waitlistID, $val);
}

// Update Notes
if ($type == $conf['NOTES']) {
	$sql_str = "update Waitlist set notes = \"$val\" where ID = $waitlistID";
	$result = mysql_query($sql_str);

	debugMsg($val);
	
	// verify
	$sql_str = "select notes from Waitlist where ID = $waitlistID";
	$result = mysql_query($sql_str);
	$row = mysql_fetch_array($result);
	$val = $row['notes'];
	
	echo getAjaxNotesHtmlResponse($entryID, $type, $waitlistID, $val);
	
}





?>